<template>
	<view class="back">
		<view style="width: 100%;height: 100%;background: #fff;margin-top: 30rpx;border-radius: 70rpx 70rpx 0rpx 0rpx;">
			<view style="height: 4vh;">
				
			</view>
			<u-popup :show="shows" @close="close" mode="center" @open="open">
							            <view style="width:600rpx;height:400rpx;padding: 20rpx;">
											<view style="float: left;">
							                <view style="margin-top: 20rpx;width: 600rpx;">
							                	锻炼部位：
							                </view>
							                <view style="float: left;margin-top: 20rpx;"  @click="drugNameShowss = true">
							                	<input type="text" v-model="typeName"
							                		style="width: 120px;height: 30px; background-color: rgb(246, 245, 245);border-radius :20rpx;text-align: center;"
							                		disabled>
							                	<u-picker :show="drugNameShowss" :columns="drugNameColumnss" @confirm="drugNameConfirmss" @cancel="closeShowss" ref="uPickerss" keyName="label"></u-picker>
							                </view>
											</view>
											<view style="float: left;">
											<view style="margin-top: 20rpx;width: 600rpx;">
												训练动作：
											</view>
											<view style="float: left;margin-top: 20rpx;"  @click="drugNameShowsss = true">
												<input type="text" v-model="actionName"
													style="width: 120px;height: 30px; background-color: rgb(246, 245, 245);border-radius :20rpx;text-align: center;"
													disabled>
												<u-picker :show="drugNameShowsss" :columns="drugNameColumnsss" @confirm="drugNameConfirmsss" @cancel="closeShowsss" ref="uPickersss" keyName="label"></u-picker>
											</view>
											<view style="height: 35rpx;float: right;margin-top: 20rpx;">
												<view style="float: right;color:#4089ff;margin-right: 40rpx;" @click="insertPlanAction">添加</view>
											</view>
											</view>
			<!-- 								<view style="margin-top: 20rpx;float: left;width: 100%;">
												已添加动作：
											</view>
											<view style="margin-top: 20rpx;float: left;width: 100%; "  v-for="(item, index) in planFrom.planActionArray" :key="index">
												<view style="float: left;">{{item.fitnessActionName}}</view>
												<view style="float: right;color:red" @click="handleDeletess(index)">删除</view>
											</view> -->
											<!-- <view style="margin-top: 20rpx;float: left;width: 100%;">
												已添加课程：
											</view>
											<view style="margin-top: 20rpx;float: left;width: 100%; " v-for="item in planFrom.planActionArray">
												<view style="float: left;">{{item.planName}}</view>
												<view style="float: right;color:red">删除</view>
												<view style="float: right;margin-right: 15rpx;color:#4089ff" @click="insertAction(item.fitnessPurposeId)">添加动作</view>
											</view> -->
							            </view>
									</u-popup>
			<view style="overflow: auto;height: 86vh;width: 100%;">
					<view @tap="openTrain(item)" style="width: 90%;background-color: #fff;margin: 0 auto;padding: 20rpx;box-sizing: border-box;box-shadow: 0 2px 10px #dfdfdf;margin-bottom: 18px;">
						<view style="height: 50rpx;">
							<view style="float: left;"><u-icon name="calendar" size="45rpx" color="#000000"></u-icon></view>
							<view style="float: left;">{{item.fitnessPlanName}}</view>
							<view style="float: right;color: #5C5C5C;font-size: 25rpx;margin-top: 5rpx;">预约时间</view>
						</view>
						<view style="width: 85vw;background-color: #F7F7F7;margin: 0 auto;height: 160rpx;padding: 5px;box-sizing: border-box;margin-top: 10rpx;">
							<view style="width: 160rpx;height: 160rpx;float: left;">
								<image class="imagg" :src="'http://101.43.223.224:8765/image/getImageById?id=6221'"></image>
							</view>
							<view style="font-size: 26rpx;float: left;color: #5C5C5C;width: 220px;">
								<view style="height: 35rpx;">
									
									<view style="float: left;">发布时间：<span>{{item.createTime}}</span><span style="margin-left:4px;">{{item.trainingTime}}</span></view>
								</view>
								<view style="margin-top:20rpx;height: 35rpx;">
									
									<view style="float: left;">教练姓名：{{item.memberUserRealName}}</view>
								</view>
							</view>
						</view>
				</view>
				<view style="width: 90%;padding: 40rpx;margin-top: -50rpx;">
				<view style="float: left;">
					课程安排
				</view>
				<!-- @tap="openTrain(item)" -->
				<view  style="float: right;width:100rpx;color:#fff;height: 50rpx; border-radius: 10rpx; background-image: linear-gradient(to bottom right, #94A9FD, #9ECFFF, #b9e1ff); display: flex; align-items: center; justify-content: center;">
				  <text style="letter-spacing: 4px;font-size: 24rpx;" @click="insert">&nbsp;+新增</text>
				</view>
				</view>
				<view style="width: 90%;background-color: #fff;margin: 0 auto;padding: 20rpx;box-sizing: border-box;box-shadow: 0 2px 10px #dfdfdf;margin-bottom: 18px;margin-top: 20rpx;" >
					<view @click="openTrain(item)" style="width: 85vw;background-color: #F7F7F7;margin: 0 auto;height: 150rpx;padding: 5px;box-sizing: border-box;margin-top: 10rpx;" v-for="item in planList">
						<view style="font-size: 26rpx;float: left;width: 90%;padding: 20rpx">
							<view style="height: 35rpx;float: left;">
								<view style="display: flex;align-items: center;"><u-icon name="calendar" size="30rpx"></u-icon>训练动作：{{item.fitnessActionName}}</view>
								<view style="display: flex;align-items: center;margin-left: 30rpx;">训练部位：{{item.fitnessTypeName}}</view>
								<view style="display: flex;align-items: center;margin-left: 30rpx;">训练组数：共{{item.fitnessActionCountAll}}组</view>
							</view>
							<view style="height: 35rpx;float: right;">
								<view style="float: right;color:red;margin-right: 40rpx;margin-top: 30rpx;" @click.stop="del(item)">删除</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				inserts:{
					group:[],
				},
				actionName:"",
				typeName:"",
				drugNameColumnsss:[
					[
						
					]
				],
				drugNameShowsss:false,
				drugNameColumnss:[
					[
						
					]
				],
				drugNameShowss:false,
				shows:false,
				item:{},
				messageText:'',
				title: 'picker',
				errTitle:'',
				selectedIndex:0,
				selectPlan:{},
				selectId:0,
				multiArray: [
				],
				index: 0,
				show: false,
				errShow:false,
				courseList: [
				],
				planList:[],
					current: 0,
					selectStatus:1,
					dayOfMonth: 0,
					daySelect: 0,
					today: '',
					msgType: 'sussess'
			}
		},
		onLoad(option) {
			this.item = JSON.parse(option.item) //打印出上个页面传递的参数。
			this.getReservation()
			this.getPlan()
			this.getAction()
		},
		onShow(){
			this.getReservation()
			this.getPlan()
			this.getAction()
		},
		methods: {
			insertPlanAction(){
				this.inserts.fitnessPlanId=this.item.id
				this.inserts.fitnessActionId=this.actionId
				this.inserts.venueUniqueIdentifier=uni.getStorageSync('teacherinfo').venueUniqueIdentifier
				console.log(this.inserts)
				var ths=this
				uni.request({
					url: this.URL+'plan/addFitnessPlanAction',
					method: 'post',
					data:ths.inserts,
					// userInfo:res.
					success: function(res) {
						ths.getPlan()
						ths.shows=false
						// for (const item of res.data.data.data) {
						// 	ths.drugNameColumnsss[0].push({
						// 		id:item.id,
						// 		label:item.fitnessActionName,
						// 	})
						// }
					},
					fail: function(error) {
						// 处理请求失败
						console.error('查询失败,请检查网络');
					}
				})
			},
			drugNameConfirmsss(e) { //病种的下拉菜单
				e.value.forEach((item, index) => {
					if (index >= 0) {
						this.actionName = item.label
						this.actionId=item.id
					} else {
						this.patientForm.drugName = ' '
					}
				})
				var ths = this;
				uni.request({
					url: this.URL+'plan/getFitnessPlanActionGroupss',
					method: 'get',
					data:{
						
						planActionId:this.actionId,
						
					},
					// userInfo:res.
					success: function(res) {
						ths.inserts.group=res.data.data
					},
					fail: function(error) {
						// 处理请求失败
						console.error('查询失败,请检查网络');
					}
				})
				this.drugNameShowsss = false
			},
			closeShowss() { //控制取消病种和生命周期的下拉菜单
				
				this.drugNameShowss = false
			},
			drugNameConfirmss(e) { //病种的下拉菜单
				e.value.forEach((item, index) => {
					if (index >= 0) {
						this.typeName = item.label
						this.typeId=item.id
					} else {
						this.patientForm.drugName = ' '
					}
				})
				var ths = this;
				uni.request({
					url: this.URL+'plan/queryByType',
					method: 'GET',
					data:{
						venueUniqueIdentifier:uni.getStorageSync('teacherinfo').venueUniqueIdentifier,
						fitnessTypeId:this.typeId,
						fitnessPurposeId:ths.item.fitnessPurposeId,
					},
					// userInfo:res.
					success: function(res) {
						for (const item of res.data.data.data) {
							ths.drugNameColumnsss[0].push({
								id:item.id,
								label:item.fitnessActionName,
							})
						}
					},
					fail: function(error) {
						// 处理请求失败
						console.error('查询失败,请检查网络');
					}
				})
				this.drugNameShowss = false
			},
			insert(){
				var ths=this
				uni.request({
					url: this.URL+'plan/getFitnessTypes',
					method: 'GET',
					data:{
						fitnessPurposeId:ths.item.fitnessPurposeId,
					},
					// userInfo:res.
					success: function(res) {
						for (const item of res.data.data.content) {
							ths.drugNameColumnss[0].push({
								id:item.id,
								label:item.fitnessTypeName,
							})
						}
					},
					fail: function(error) {
						// 处理请求失败
						console.error('查询失败,请检查网络');
					}
				})
				this.shows=true
			},
			open() {
			},
			close() {
				this.shows=false
			},
			del(item){
				var ths=this
				uni.request({
					url: this.URL+'plan/deleteFitnessPlanAction',
					method: 'delete',
					data: item,
					// userInfo:res.
					success: function(res) {
						if(res.data.code==200){
							
							ths.getPlan()
						}else{
							
						}
						
					},
					fail: function(error) {
						// 处理请求失败
						console.error('删除失败');
					}
				})
			},
			fan(){
				uni.navigateBack({
				        delta: 1 // 返回的页面数，这里是返回上一页，所以是1
				    });
			},
			getAction() {
				
			},
			selectUser(item){
				this.selectId=item.id
			},
			handleChange(event) {
				const selectedIndex = event.detail.value; // 获取选中的索引
				const selectPlan = this.planList[selectedIndex]; // 获取选中的对象数据
				var ths = this;
				uni.request({
					url: this.URL+'vipPlan/memberAddPlan',
					method: 'POST',
					data: {
						memberId: ths.selectId,
						seriesId: selectPlan.id
					},
					// userInfo:res.
					success: function(res) {
						if(res.data.code==200){
							this.getReservation()
							ths.show=true
							setTimeout(() => {
							        ths.show = false;
							      }, 2000);
						}else{
							ths.errShow=true
							ths.errTitle=res.data.data
							setTimeout(() => {
							        ths.errShow = false;
							      }, 2000);
						}
						
					},
					fail: function(error) {
						// 处理请求失败
						console.error('角色查询失败,请检查网络');
					}
				})
				
			},
			getReservation(){
				var ths = this;
				uni.request({
					url: this.URL+'AppCoach/getStudentByTeacherId',
					method: 'GET',
					data: {
						coachCode: uni.getStorageSync('teacherinfo').coachCode,
					},
					// userInfo:res.
					success: function(res) {
						ths.courseList = res.data.data;
					},
					fail: function(error) {
						// 处理请求失败
						console.error('角色查询失败,请检查网络');
					}
				})
			},
			getPlan(){
				var ths = this;
				uni.request({
					url: this.URL+'plan/getFitnessPlanAction',
					method: 'GET',
					data: {
						fitnessPlanId: this.item.id,
					},
					// userInfo:res.
					success: function(res) {
						ths.planList = res.data.data.content;
						console.log(ths.planList)
					},
					fail: function(error) {
						// 处理请求失败
						console.error('角色查询失败,请检查网络');
					}
				})
			},
			goSearch() {	
				
			},
			openTrain(item){
				uni.navigateTo({
					url: '/pages/coach/class/count?item='+JSON.stringify(item)
				})
			},
		}
	}
</script>

<style>
	.title {
			font-size: 14px;
			font-weight: bold;
			margin: 20px 0 5px 0;
		}
	.data-pickerview {
			height: 400px;
			border: 1px #e5e5e5 solid;
		}
	
		 .popper__arrow {
	    top: -6px;
	    left: 50%;
	    margin-right: 3px;
	    border-top-width: 0;
	    border-bottom-color: #EBEEF5;
	}
	 .popper__arrow {
	    top: -6px;
	    left: 50%;
	    margin-right: 3px;
	    border-top-width: 0;
	    border-bottom-color: #EBEEF5;
	}

	.div2{
		width: 100%;
		height: 5vh;
	}
	.div2-2{
		background-color:#fff;
		border-radius: 20px 20px;
		height: 70rpx;
		width: 90%;
		margin: 0 auto;
	}
/* ::v-deep .div2-2 .input-placeholder {
    color: #FFF;
} */
.week-display {
	display: flex;
	justify-content: space-between;
	color: #fff;
	width: 90%;
	height: 8vh;
	margin: 0 auto;
	margin-top: 2vh;
}

.week-item {
	flex: 1;
	text-align: center;
}

.back {
	position: relative;
	width: 100%;
	height: 100vh;
	overflow: hidden; /* 超出部分隐藏，可根据需求调整 */
}

.homeclick{
	height: 70rpx;
	width: 70rpx;
	margin-top: 20rpx;
}
.dao{
	 float: left;
	 width: 50%;
	 margin: 0 auto;
	 margin-top: 20rpx;
	 height: 45rpx;
	 font-size: 25rpx;
}
.dao-1{
	 border-bottom: skyblue 3px solid;
	 width: 30%;
	 margin: 0 auto;
	 height: 45rpx;
	 display: flex;
	 justify-content: center;
	 align-items: center;
}
.dao-2{
	 width: 30%;
	 margin: 0 auto;
	 height: 45rpx;
	 display: flex;
	 justify-content: center;
	 align-items: center;
}
.imagg{
	 width: 140rpx;
	 height: 140rpx;
	 border-radius: 4px;
}
</style>
